package cn.doitedu.demo7;

import cn.doitedu.beans.UserAction;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.flink.api.common.functions.RuntimeContext;
import org.apache.flink.util.Collector;

import java.io.IOException;



public class RuleModelCalculator_New implements RuleCalculator{

    String triggerEventId;
    String ruleId;

    @Override
    public String ruleId() {
        return ruleId;
    }

    @Override
    public boolean isNeedProcessPastData() {
        return false;
    }

    @Override
    public void init(RuntimeContext runtimeContext, RuleMeta ruleMeta) throws IOException {
        String ruleParamJson = ruleMeta.getRule_param_json();
        JSONObject jsonObject = JSON.parseObject(ruleParamJson);

        triggerEventId = jsonObject.getString("trigger_event_id");
        ruleId = jsonObject.getString("rule_id");
    }

    @Override
    public void calc(UserAction userAction, Collector<String> out) throws IOException {

        if(userAction.getEvent_id().equals(triggerEventId)){
            out.collect("我爱你");
        }
    }
}
